<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="员工" prop="userId">
        <UserDialog v-model="queryParams.userId"></UserDialog>
      </el-form-item>
      <el-form-item label="部门" prop="deptId">
        <el-cascader
          :props="{ value: 'id', checkStrictly: true }"
          :show-all-levels="false"
          placeholder="请选择部门"
          v-model="deptId"
          :options="deptOptions"
        ></el-cascader>
      </el-form-item>
      <!-- <el-form-item label="审批状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择审批状态">
          <el-option
            v-for="dict in dict.type.sys_comp_fee_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <!-- <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['personnel:zzsqList:add']"
          >新增</el-button
        > -->
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['personnel:zzsqList:edit']"
          >修改</el-button
        >
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['personnel:zzsqList:remove']"
          >删除</el-button
        >
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['personnel:zzsqList:export']"
          >导出</el-button
        >
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      @selection-change="handleSelectionChange"
      fit
      v-loading="loading"
      border
      :data="dataList"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column show-overflow-tooltip label="流程状态" width="100">
        <template slot-scope="scope">
          <el-tag size="mini">{{ scope.row.statusName }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="单据编号" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-link @click="handleDetail(scope.row)" type="primary">{{
            scope.row.applyNo
          }}</el-link>
        </template>
      </el-table-column>
      <el-table-column
        :show-overflow-tooltip="true"
        label="部门"
        prop="deptName"
      />
      <el-table-column
        :show-overflow-tooltip="true"
        label="姓名"
        prop="nickName"
      />
      <el-table-column
        :show-overflow-tooltip="true"
        label="申请时间"
        prop="applyDate"
      />
      <el-table-column
        :show-overflow-tooltip="true"
        label="入职日期"
        prop="startDate"
      />
      <el-table-column
        :show-overflow-tooltip="true"
        label="申请转正日期"
        prop="toOfficialDate"
      />

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="200"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            v-hasPermi="['personnel:zzsqList:info']"
            @click="handleDetail(scope.row)"
            >详情</el-button
          >
          <!-- <el-button
            size="mini"
            type="text"
            v-if="scope.row.status === 'refuse'"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['personnel:zzsqList:edit']"
            >修改</el-button
          > -->

          <!--
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['personnel:zzsqList:remove']"
            >删除</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listOfficialApply,
  delOfficialApply,
} from "@/api/finance/personnel/officialApply.js";
import { userSelect, deptTreeSelect } from "@/api/system/user.js";

export default {
  name: "Bxgl",
  dicts: ["sys_comp_fee_status"],

  data() {
    return {
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      dataList: [],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        feeNo: undefined,
        feeName: undefined,
        projectName: undefined,
      },
      // 日期范围
      dateRange: [],

      userList: [],
      deptOptions: [],
      deptId: [],
    };
  },
  created() {
    this.getList();
    this.userSelect();
    this.getDeptTree();
  },
  methods: {
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.laborOfficialApplyId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      const configId = row.laborOfficialApplyId || this.ids;
      this.$router.push("./zzsq?iszzlist=1&isEdit=true&id=" + configId);
    },
    handleDetail(row) {
      // this.$router.push(
      //   "./zzsq?iszzlist=1&isInfo=true&id=" + row.laborOfficialApplyId
      // );
      this.$router.push({
        path: "/zzsq/process/detail/" + row.piid,
        query: {
          definitionId: null,
          deployId: null,
          taskId: null,
          finished: false,
          id: row.laborOfficialApplyId,
        },
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const configId = row.laborOfficialApplyId || this.ids;
      let e = this.dataList.find((i) => i.laborOfficialApplyId == configId);
      console.log(e);
      this.$modal
        .confirm('是否确认删除姓名为"' + e.nickName + '"的数据项？')
        .then(function () {
          return delOfficialApply(configId);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    handleAdd() {
      this.$router.push("./zzsq?iszzlist=1");
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
    userSelect() {
      userSelect().then((response) => {
        this.userList = response.data;
      });
    },
    /** 查询列表 */
    getList() {
      this.loading = true;

      this.queryParams.deptId = this.deptId[this.deptId.length - 1];

      listOfficialApply(
        this.addDateRangeTime(
          this.queryParams,
          this.dateRange,
          "startFeeDate",
          "endFeeDate"
        )
      ).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.deptId = [];

      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleExport() {
      this.download(
        "system/officialApply/export",
        {
          ...this.queryParams,
        },
        `转正申请审批记录表_${this.parseTime(
          new Date().getTime(),
          "{y}-{m}-{d}"
        )}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
  img {
    width: 100%;
  }
}
</style>
